package com.p2p.cms.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.p2p.base.page.PageVo;
import com.p2p.cms.dao.CategoryDao;
import com.p2p.cms.dao.PostDao;

@Service
public class PostService {

	@Autowired
	private PostDao postDao;

	@Autowired
	private CategoryDao categoryDao;

	/******************* 查询 *****************/
	public Map<String, Object> get(Integer id) {
		return postDao.get(id);
	}

	public List<Map<String, Object>> listRecent(Integer categoryId,
			Integer count) {
		if(count ==null || count>10){
			count = 5;
		}
		List<Map<String, Object>> postList = postDao.listRecent(categoryId,
				count);
		return postList;
	}
	public List<Map<String, Object>> listTitleByCategoryId(Integer categoryId,
			Integer count) {
		if(count ==null || count>10){
			count = 5;
		}
		List<Map<String, Object>> postList = postDao.listTitleByCategoryId(categoryId,
				count);
		return postList;
	}

	
	public PageVo page(PageVo page) {
		List<Map<String, Object>> list = postDao.listPage(page);
		page.setList(list);
		return page;
	}

	public PageVo pageAdmin(PageVo page) {
		List<Map<String, Object>> list = postDao.listPageAdmin(page);
		page.setList(list);
		return page;
	}
	
	/******************* 修改 *****************/
	public void add(Map<String, Object> post) {
		postDao.add(post);
	}

	public void update(Map<String, Object> post) {
		postDao.update(post);
	}

	public void remove(Integer id) {
		postDao.remove(id);
	}


}
